<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <!--引入本地的css样式-->
  <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../static/css/admin.css" media="all">
</head>
<body>
<div class="layui-fluid">
  <div class="layui-card">
    <form id="myform" class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
      <!--id在页面中隐藏了，前端传递给后端也传递了id值  -->
      <input type="hidden" name="id">
      <input type="hidden" name="customer_code">
      <!--客户姓名 性别-->
      <div class="layui-form-item">
        <label class="layui-form-label"><b>客户姓名：</b></label>
        <div class="layui-input-inline">
          <input type="text" name="customer_name" disabled autocomplete="off" class="layui-input">
        </div>
        <label class="layui-form-label required"><b>性别：</b></label>
        <div class="layui-input-inline">
          <input type="text" name="sex" disabled autocomplete="off" class="layui-input">
        </div>
      </div>
      <!--客户类型 客户状态-->
      <div class="layui-form-item" pane="">
        <label class="layui-form-label required"><b>客户类型：</b></label>
        <div class="layui-input-inline">
          <input type="text" name="type" disabled autocomplete="off" class="layui-input">
        </div>
        <label class="layui-form-label required"><b>客户状态：</b></label>
        <div class="layui-input-inline">
          <input type="text" name="status" disabled autocomplete="off" class="layui-input">
        </div>
      </div>
      <!--生日 满意度-->
      <div class="layui-form-item" pane="">
        <label class="layui-form-label required"><b>生日：</b></label>
        <div class="layui-input-inline">
          <input type="text" name="birth" disabled autocomplete="off" class="layui-input">
        </div>
        <label class="layui-form-label required"><b>满意度：</b></label>
        <div class="layui-input-inline">
          <input type="text" name="total_satisfaction" disabled autocomplete="off" class="layui-input">
        </div>
      </div>
      <!--信誉等级-->
      <div class="layui-form-item" pane="">
        <label class="layui-form-label required"><b>信誉等级：</b></label>
        <div class="layui-input-inline">
          <input type="text" name="reputation_level" disabled autocomplete="off" class="layui-input">
        </div>
      </div>
      <hr>
    </form>
    <div class="layui-card-body">
      <!--头部工具栏 id="toolbarDemo" lay-event="事件名"-->
      <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
          <!-- lay-event 给元素绑定事件名 -->
          <button class="layui-btn layuiadmin-btn-admin" lay-event="add">
            添加
          </button>
          <button class="layui-btn layuiadmin-btn-admin" lay-event="update">
            修改
          </button>
          <button class="layui-btn layuiadmin-btn-admin" lay-event="del">
            删除
          </button>
          <button class="layui-btn layuiadmin-btn-admin" lay-event="back">
            返回
          </button>
        </div>
      </script>

      <!--数据表格-->
      <table class="layui-hide" id="LAY-care-back-manage" lay-filter="LAY-care-back-manage"></table>

    </div>
  </div>
</div>

<script src="../../static/js/jquery-3.6.0.min.js"></script>
<!--引入本地layui.js-->
<script src="../../static/layui/layui.js"></script>
<!--js-->
<script type="text/javascript">
    layui.config({
        base: '../../static/layui/layuiadmin/' //静态资源所在路径js
    }).extend({
        index: 'lib/index' //主入口模块
    }).use('index');
</script>

<script type="text/javascript">

    let customer_data = JSON.parse(sessionStorage.getItem("cData"))[0];
    console.log(customer_data);
    $("input[name=id]").val(customer_data.id);
    $("input[name=customer_code]").val(customer_data.customer_code);
    $("input[name=customer_name]").val(customer_data.customer_name);
    if(customer_data.sex==1){
        $("input[name=sex]").val("男");
    }else if(customer_data.sex==2){
        $("input[name=sex]").val("女");
    }
    $("input[name=type]").val(customer_data.type);
    if(customer_data.status==1){
        $("input[name=status]").val("正常");
    }else if(customer_data.status==2){
        $("input[name=status]").val("删除");
    }
    $("input[name=birth]").val(customer_data.birth);
    $("input[name=total_satisfaction]").val(customer_data.total_satisfaction);
    $("input[name=reputation_level]").val(customer_data.reputation_level);

    layui.use(['table','form'],function () {
        var table = layui.table;
        var form = layui.form;
        //表格方法渲染：把数据查询显示在数据表格中
        table.render({
            elem: '#LAY-care-back-manage',//绑定在哪一个table表中,#id值
            url: '/customer_care/care_remind/care_remind',//绑定servlet路径
            title: '客户订单信息表',//标题
            toolbar:'#toolbarDemo',//头部工具栏
            cols: [[
                //设置复选框列
                {field: 'remind_status', title: 'remind_status',type: 'checkbox', fixed: 'left'},
                //设置表头
                {field: 'id', title: 'ID', fixed: 'left', unresize: true, sort: true, width: 80},
                {field: 'remind_name', title: '提醒名称'},
                {field: 'remind_time', title: '提醒时间'},
                {field: 'remind_type', title: '提醒类型'},
                {field: 'remind_rate', title: '提醒频率'},
            ]],
            where:{"customer_code":customer_data.customer_code},
            page: true,
            limits: [5, 10, 15, 20]
        })

        // 监听头部工具栏
        table.on('toolbar(LAY-care-back-manage)',function (obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            switch (obj.event){
                case 'back':
                    window.location.href = "customer_care.html";
                    break;
                case 'add':
                    layer.open({
                        type:2,//iframe层
                        title:'添加房产信息',
                        content:'add.html',//展示编辑页面
                        area:['700px','550px'],
                        maxmin:true,
                        btn:['确定','取消'],
                        yes:function (index, layero){
                            //应该把edit.html页面表单的数据提交给服务器
                            //在当前页面-list.html获取iframe层-edit.html的DOM-form表单
                            var body = layer.getChildFrame('body', index);
                            //获取edit.html页面中所有表单的数据
                            var submitData = body.find("#myform").serialize();//serialize()只能序列化表单中文本
                            //发起Ajax请求
                            $.ajax({
                                url:"/customer_care/care_remind/add",
                                type:"post",
                                data:submitData,
                                dataType: "json",
                                success:function (res){
                                    if(res.code==200){
                                        layer.msg(res.msg,{
                                            offset:'15px',
                                            icon:1,
                                            time:1000
                                        },function (){
                                            //刷新
                                            window.location.reload();
                                        })
                                    }
                                    if(res.code==500){
                                        layer.msg(res.msg,{
                                            offset:'15px',
                                            icon:1,
                                            time:1000
                                        },function (){
                                            //刷新
                                            window.location.reload();
                                        })
                                    }
                                    layer.close(index);//关闭弹层
                                }
                            })
                        }
                    })
                    break;
                case 'update':
                    if(data.length<1){
                        layer.msg('您还未选中修改的数据')
                    } else if(data.length>1){
                        layer.msg('只能选中一条数据修改')
                    } else{
                        layer.open({
                            type: 2,//iframe层
                            title: '编辑客户资源',
                            content: 'edit.html',//展示编辑页面
                            area: ['700px', '550px'],
                            maxmin: true,
                            btn: ['确定', '取消'],
                            yes: function (index, layero) {
                                //应该把edit.html页面表单的数据提交给服务器
                                //在当前页面-list.html获取iframe层-edit.html的DOM-form表单
                                var body = layer.getChildFrame('body', index);
                                //获取edit.html页面中所有表单的数据
                                var submitData = body.find("#myform").serialize();//serialize()只能序列化表单中文本
                                //发起Ajax请求
                                $.ajax({
                                    url: "/customer_care/care_remind/update",
                                    type: "post",
                                    data: submitData,
                                    dataType: "json",
                                    success: function (res) {
                                        if (res.code == 200) {
                                            layer.msg(res.msg, {
                                                offset: '15px',
                                                icon: 1,
                                                time: 1000
                                            }, function () {
                                                //刷新
                                                window.location.reload();
                                            })
                                        }
                                        if (res.code == 500) {
                                            layer.msg(res.msg, {
                                                offset: '15px',
                                                icon: 1,
                                                time: 1000
                                            }, function () {
                                                //刷新
                                                window.location.reload();
                                            })
                                        }
                                        layer.close(index);//关闭弹层
                                    }
                                })
                            },
                            success: function (layero, index) {//子页面edit.html页面数据回显
                                var body = layer.getChildFrame('body', index);
                                var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                                //input控件的输入框/隐藏框
                                body.find("input[name=customer_code]").val(data[0].customer_code);
                                body.find("input[name=customer_name]").val(data[0].customer_name);
                                body.find("input[name=remind_name]").val(data[0].remind_name);
                                body.find("input[name=remind_time]").val(data[0].remind_time);
                                body.find("option[value=" + data[0].remind_type + "]").attr("selected", true);
                                if (data[0].remind_cycle.charAt(0) == 1) {
                                    body.find("input[value='周一']").attr("checked", true)
                                }
                                if (data[0].remind_cycle.charAt(1) == 1) {
                                    body.find("input[value='周二']").attr("checked", true)
                                }
                                if (data[0].remind_cycle.charAt(2) == 1) {
                                    body.find("input[value='周三']").attr("checked", true)
                                }
                                if (data[0].remind_cycle.charAt(3) == 1) {
                                    body.find("input[value='周四']").attr("checked", true)
                                }
                                if (data[0].remind_cycle.charAt(4) == 1) {
                                    body.find("input[value='周五']").attr("checked", true)
                                }
                                if (data[0].remind_cycle.charAt(5) == 1) {
                                    body.find("input[value='周六']").attr("checked", true)
                                }
                                if (data[0].remind_cycle.charAt(6) == 1) {
                                    body.find("input[value='周日']").attr("checked", true)
                                }
                                body.find("option[value=" + data[0].remind_rate + "]").attr("selected", true);
                                body.find("textarea[name=remark]").val(data[0].remark);
                                //刷新渲染  重要！！！！
                                iframeWin.layui.form.render();
                            }
                        })
                    }
                    break;
                case 'del':
                    var data = checkStatus.data;
                    if(data.length<1){
                        layer.msg('您还未选中删除的数据')
                    }else{
                        //删除：提示确认框，发起Ajax请求
                        layer.confirm('确定要删除选中行数据吗?',function (index){
                            var ids = new Array();
                            $.each(data,function (index,item){
                                //循环遍历选中的数据，只要数据的id，把id塞入到数组中
                                ids.push(item.id);
                            })
                            //发起Ajax请求
                            $.ajax({
                                url:"/customer_care/care_remind/del",
                                type:"post",
                                data:{ids:ids},
                                traditional: true,//数组进行传统的序列化操作
                                dataType:"json",
                                success:function (res){
                                    layer.msg(res.msg,{
                                        offset:'15px',
                                        icon:1,
                                        time:1500
                                    },function (){
                                        //刷新
                                        window.location.reload();
                                    })
                                }
                            })
                        })
                    }
                    break;
            }
        })
    })
</script>
</body>
</html>